﻿/*
 * Created by SharpDevelop.
 * User: Administrator
 * Date: 2010-7-5
 * Time: 22:47
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Text;

using AjaxPro;

namespace ECCIT.Utilities
{
    /// <summary>
    /// Description of 
    /// </summary>
    [Serializable]
    [AjaxNamespace("StringUtil")]
    public sealed class StringUtil
    {
        // empty constructor for AjaxPro
        public StringUtil() { }

        public static string SafeToString(object obj)
        {
            return SafeToString(obj, string.Empty);
        }

        public static string SafeToString(object obj, string nullText)
        {
            return (null == obj) ? nullText : obj.ToString();
        }

        public static string FromBase64String(string encodedString, Encoding encoding)
        {
            byte[] b = Convert.FromBase64String(encodedString);
            string decodedString = encoding.GetString(b);
            return decodedString;
        }

        public static string ToBase64String(string str, Encoding encoding)
        {
            byte[] b = encoding.GetBytes(str);
            return Convert.ToBase64String(b);
        }
    }
}
